#include <iostream>
#include <cstdlib>
#include <GL\glut.h>
#include "objModel.h"
#include "glModel.h"
#include "glTriModel.h"
#pragma comment(lib,"glut32.lib");
		objModelReader *reader= new objModelReader;
		glModel *model;
		glTriModel *TriModel;
bool ModelReady=false;

void RenderScene(void){
	
	glClear(GL_COLOR_BUFFER_BIT);

		if(ModelReady){
			TriModel->setPrimitivesColor(255,255,0,25);
			TriModel->RenderingModel();
		}

	glutSwapBuffers();

}
void MouseProcessFunc(int button,int state,int x, int y){
	printf("button %i = %i at %i,%i\n",button,state,x,y);

}



void SetupRC(void){
	glClearColor(0.0f,0.0f,0.0f,1.0f);
}


void changeSize(GLsizei w, GLsizei h){
	GLfloat aspectRatio;


	if(h==0)
		h=1;
	glViewport(0,0,w,h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();


	aspectRatio =(GLsizei)w/(GLsizei)h;
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	

	 gluPerspective(120.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0); 
	 gluLookAt(4.0,4.0,4.0,0.0,0.0,0.0,0.0,1.0,0.0);

}


int main(int argc, char* argv[]){

	reader->loadFile("head.obj");
	model= reader->CopyModel();
	if(model->isTriMesh()){
		TriModel= model->Copy2TriModel();
		ModelReady=true;
		delete model;
		delete reader;
	}
	else
	{
		printf("The Model you load is no Tri-Mesh!! can not process!!!\n ");

	}





	

	glutInit(&argc,argv);
	//glutInit(800,600);
	glutInitWindowSize(800,600);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);

	glutCreateWindow("First OpenGL Program");
	
	glutDisplayFunc(RenderScene);
	glutReshapeFunc(changeSize);
	glutMouseFunc(MouseProcessFunc);
	
	
	glEnable (GL_BLEND); 
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		SetupRC();


	

	glutMainLoop();
	return 0;

}